package com.db.user.controller;

import com.db.core.vo.R;
import com.db.user.entity.User;
import com.db.user.service.UserService;
import com.db.user.utils.GetJwtToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 作者：Bin
 * 时间：2023/10/27
 * 描述：键盘敲烂，薪资过万
 */
@RestController
@RequestMapping("user")
@CrossOrigin
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("login")
    public R login(@RequestBody User user){
        return userService.login(user);
    }

    @RequestMapping("verify")
    public R verify(@RequestHeader String token){

        try {
            GetJwtToken.verify(token);
            return  R.ok("valid token");
        }catch (Exception e){
            e.printStackTrace();
            return  R.fail("invalid token");
        }

    }
}
